## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
## edited by TAFirehawk, Mrgenie, Torin, Rockinroger, Keldath

from CvPythonExtensions import *
import CvUtil
import PyHelpers
import CvEventManager
import sys
import CvGreatPersonScreen
import RandomNameUtils
import CvConfigParser		

gc = CyGlobalContext()

PyPlayer = PyHelpers.PyPlayer


# globals
###################################################
class CvGreatPersonModEventManager:

	def __init__(self, eventManager):

                global g_bGreatPersonModFeaturesEnabled

                config = CvConfigParser.CvConfigParser("ViSa-Component-Control.ini")

		if(config != None):
			g_bGreatPersonModFeaturesEnabled = config.getboolean("ViSa Component Control", "Great Person Splash", True)

		eventManager.addEventHandler("greatPersonBorn", self.onGreatPersonBorn)

	"""
	# Test code to make sure that we can go through the vanilla great person
	# names and test the random names
	def onMouseEvent(self, argsList):
	
		gc.getPlayer(0).getCapitalCity().createGreatPeople(gc.getInfoTypeForString("UNIT_ARTIST"), true)
	"""		

	# GreatPerson Mod -------- begin
	def onGreatPersonBorn(self, argsList):
			
		'Great Person Born'
		pUnit, iPlayer, pCity = argsList
		player = PyPlayer(iPlayer)

		if(not g_bGreatPersonModFeaturesEnabled):
			return

		# If we're running in AIAutoPlay mode we don't want these popups to Appear
		if (not CyGame().getAIAutoPlay() == 0 ):
                        return
                
		# Check if we should even show the popup:
		if pUnit.isNone() or pCity.isNone():
			return

		#disable popups for special units granted on techs, Monument MOD
		if (pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_PALADIN") or \
		    pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_LANDSKNECHT") or \
		    pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_ZEPPELIN") or \
		    pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_ZEPPELIN3") or \
		    pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_MODERN_ARMOR_SNOW") or \
		    pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_MODERN_ARMOR_DESERT") or \
		    pUnit.getUnitType() == gc.getInfoTypeForString("UNIT_FLAK88")):
			return

		#If Person doesn't have unique name, give him a random one
		if(len(pUnit.getNameNoDesc()) == 0):
		    iCivilizationType = player.player.getCivilizationType()
		    pUnit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
		    szPersonName = "Great Person"               
		
		else:                   
			szPersonName = pUnit.getNameNoDesc()		

		#Show fancy lil popup if *we* got the great person:
		iActivePlayer = CyGame().getActivePlayer()
		if iActivePlayer == iPlayer:
			CvGreatPersonScreen.CvGreatPersonScreen().interfaceScreen(pUnit, pCity, szPersonName)

